/**可显示对象类
 * MBasice,MWindow,MScene,MLayer,MSlide,MLabel,MProgress,MSprite,MToggleContainer
 * MShape,MSureCancel,MScorll,MTabbar,MAlert,MImage,MStroke
 * MButton,MCircleButton,MMoreButton,MToggle
 * 提示类MUtil
 * MUtil.warn(),MUtil.alert(),MUtil.sureCancel()
 * 运动类MTween
 * MTween.to(),MTween.by(),MTween.set(mc).go(100,{}).start();
 * MTween.set(node).go(100,{y:y1}).go(60,{y:y2}).start();
 * 事件cuiEvent
 * 有cuiEvent.addEvent(),cuiEvent.emitEvent(),cuiEvent.removeEvent()
 * 颜色常量mColor
 * 注意事项
 * 首先要初始化
 * 例如
 * var stage = createui.initStage(canvas,update);//canvas为html的标签,update为刷屏函数
 * 所有类在构造函数中都要默认传入{}空对象，如果传参数如传入宽则是{width:100}
 * 例如 new MButton({});new MScene({});new MSlide({});等都要默认传入{}
 * 必须先加相关类包，比如使用Laya时，需要先加载Laya的库，再加载createui库
 * 例如
 * 使用Laya
 * <script src="../libs/laya.core-2.12.2.js"></script>
 * <script src="../libs/createui.js"></script>
 * 使用createjs
 * <script src="../libs/easeljs.js"></script>
 * <script src="../libs/createui.js"></script>
 * author：ywx620
 * web:https://ywx620.gitee.io/learn/
 * 优化方法https://tw93.fun/2018-07-28/createjs.html
 * 开启触控createjs.Touch.enable(stage);
 */
class DEMOUI{}
const createui={
	Container:DEMOUI,
	Shape:DEMOUI,
	Text:DEMOUI,
	Point:DEMOUI,
}
const uistat={
	createjs:1,
	laya:2,
	egret:3,
	cocos2d:4,
}
const uiconfig={
	roundAngle:5//圆角度数
}
var uiStatus=0;
if(window['createjs']){//完美支持
	uiStatus=uistat.createjs;
	createui.Container=createjs.Container;
	createui.Shape=createjs.Shape;
	createui.Text=createjs.Text;
	createui.Point=createjs.Point
}else if(window['Laya']){//大部分支持
	uiStatus=uistat.laya;
	createui.Container=Laya.Sprite;
	createui.Shape=Laya.Sprite;
	createui.Text=Laya.Text;
	createui.Point=Laya.Point;
}else if(window['egret']){//暂未开发
	uiStatus=uistat.egret;
	createui.Container=egret.Sprite;
	createui.Shape=egret.Shape;
	createui.Text=egret.Text;
	createui.Point=egret.Point;
}else if(window['cc']){//暂未开发
	uiStatus=uistat.cocos2d;
	createui.Shape=cc.DrawNode
}
//console.log(createui.Shape)
createui.init=(stage)=>{//初始化参数在外部定义stage=new createjs.Stage(canvas);再传进来
	createui.stage=stage;
	createjs.Touch.enable(stage);//支持手机上触控事件
	if(stage.canvas){
		createui.stageWidth=createui.stage.canvas.width;
		createui.stageHeight=createui.stage.canvas.height;
	}else{
		createui.stageWidth=createui.stage.width;
		createui.stageHeight=createui.stage.height;
	}
	if(uiStatus===uistat.createjs){
		createui.stage.enableMouseOver(30);//启动鼠标移入移出等事件
	}
}
createui.initStage=(canvas,callBack)=>{//初始化场景
	if(uiStatus===uistat.createjs){
		var stage=new createjs.Stage(canvas);
		createjs.Ticker.framerate = 60;
		createjs.Ticker.addEventListener("tick",(e)=>{
			stage.update();
			callBack&&callBack(e.delta);//e.delta为帧频率(类似cocos2d里面的update(dt)中的dt)
		});
	}else if(uiStatus===uistat.laya){
		Laya.init(canvas.width,canvas.height);
		var stage=Laya.stage;
	}
	createui.init(stage);
	return stage;
}
const mColor={
	colorNormal:'#333333',//正常色（弹起色）
	colorOver:'#444444',//滑过色
	colorDown:'#555555',//按下色
	colorNoActive:'#666666',//
	colorBack:'#E86C38',//背景色
	colorFront:'#222222',//前景色
	colorFont:'#ffffff'//字体色
}
const mConst={
	CLICK:'click',
	MOUSEDOWN:'mousedown',
	MOUSEUP:'pressup',
	START:'start',
	MOVE:'move',
	OVER:'over',
	CHANGE:'change',
	COMPLETE:'complete',
}
const mUnify={
	getPiexl:(x,y)=>{//获取像素颜色,返回rbga数组
		let context=createui.stage.canvas.getContext("2d");
		let pixel = context.getImageData(x, y, 1, 1).data;
		return pixel;
	}
}
const cuiEvent={
	sureCancel:"Event-MSureCancel",
	addEvent:(target,eventType,callBack,thisObj)=>{
		if(uiStatus===uistat.createjs){
			target.addEventListener(eventType,callBack.bind(thisObj));
		}else if(uiStatus===uistat.laya){
			target.on(eventType,thisObj,callBack.bind(thisObj));
		}
	},
	emitEvent:(target,eventType,data)=>{
		if(uiStatus===uistat.createjs){//createjs要使用参数,可以用target.data={}方法来传送
			target.dispatchEvent(eventType);//内部不支持传参
		}else if(uiStatus===uistat.laya){//laya可以使用参数data
			target.event(eventType,data);//内部支持传参
		}
	},
	removeEvent:(target,eventType,callBack,thisObj)=>{
		if(uiStatus===uistat.createjs){
			target.removeEventListener(eventType,callBack.bind(thisObj));
		}else if(uiStatus===uistat.laya){
			target.off(eventType,thisObj,callBack.bind(thisObj));
		}
	}
}
const MUtil={}
//居中的无确定按钮的提醒框
MUtil.warn=(str,time=1500)=>{
	if(!createui.stage){console.error('createui.stage未赋值');return;}
	if(!this.tips)this.tips=[];
	let stage=createui.stage;
	let viewer=new MTipBg({width:300,height:50,bottomHeight:10,topHeight:0});
	let [x,y]=[(createui.stageWidth-viewer.width)>>1,(createui.stageHeight-viewer.height)>>1];
	viewer.setPos(x,y).setText(str)
	stage.addChild(viewer);
	this.tips.push(viewer);
	let len=this.tips.length-1;
	for(let i=len;i>=0;i--){
		let v=this.tips[i];
		v.y=y-v.height*(len-i);
	}
	setTimeout(()=>{
		let v=this.tips.shift();
		MTween.to(v,{alpha:0,y:v.y-100},1000,()=>{
			v.destroy();
		})
	},time)
}
//居中的有确定按钮的提醒框
MUtil.alert=(str)=>{
	if(!createui.stage){console.error('createui.stage未赋值');return;}
	let stage=createui.stage;
	var viewer=new MAlert({label:str,width:300,height:100});
	let [x,y]=[(createui.stageWidth-viewer.width)>>1,(createui.stageHeight-viewer.height)>>1];
	viewer.setPos(x,y).noEventBg();
	stage.addChild(viewer);
	return viewer;
}
//居中的有确定与取消按钮的提醒框
MUtil.sureCancel=(str,callBack)=>{
	if(!createui.stage){console.error('createui.stage未赋值');return;}
	let stage=createui.stage;
	var viewer=new MSureCancel({label:str,width:300,height:200});
	let [x,y]=[(createui.stageWidth-viewer.width)>>1,(createui.stageHeight-viewer.height)>>1];
	viewer.setPos(x,y).noEventBg();
	viewer.setCallBack(callBack);
	stage.addChild(viewer);
	return viewer;
}
const MTween={}//时间线的属性改变器
//MTween.set(btn).go(100,{x:150}).go(500).go(100,{y:150}).start();
MTween.set=function(item,type='to',mOverBack){
	this.item=item;
	this.item.mType=type;
	this.item.datas=[];
	this.item.mOverBack=mOverBack;
	return this;
}
MTween.go=function(time,data){
	let item=this.item;
	if(item)item.datas.push({time:time,data:data});
	return this;
}
MTween.every=function(callBack){//每一次结束都回调
	if(this.item)this.item.mEveryCb=callBack;
}
MTween.over=function(callBack){//最后一次结束才回调
	if(this.item)this.item.mOverBack=callBack;
}
MTween.stop=function(){

}
MTween.start=function(isLoop=false){//开始动画
	let item=this.item;
	let self=this;
	let cnt=0;
	cb();
	function cb(){
		if(item){
			if(cnt<item.datas.length){
				let {time,data}=item.datas[cnt++];
				if(data)item.mType=='to'?self.to(item,data,time,cb):self.by(item,data,time,cb);
				else setTimeout(cb,time);
			}else{
				if(item.mOverBack)item.mOverBack();
				if(isLoop){
					cnt=0;cb();
				}
			}
			if(item.mEveryCb)item.mEveryCb();
		}
	}
}
MTween.remove=function(item){
	clearTimeout(item.mTime);
	item.datas=null;
	item.mLoop=null;
	item.mTime=null;
	if(this.item==item){
		this.item=null;
	}
}
/**时间线动画[[time,{item,time,data,callBack}]],此方法不推荐使用，推荐使用MTween.set(btn).go(100,{x:150}).go(100,{y:150}).start();*/
MTween.timeLine=(arr)=>{
	let time=0;
	for(let i=0;i<arr.length;i++){
		let da=arr[i];
		let d=da[1];
		time+=da[0];
		if(i>0)time+=d.time||0;
		setTimeout(()=>{
			if(d.type=='to'){
				MTween.to(d.item,d.data,d.time,d.callBack);
			}else{
				MTween.by(d.item,d.data,d.time,d.callBack);
			}
		},time);
	}
}
MTween.to=(item,data,time,callBack)=>{
	let values={};
	for(let i in data){
		let num=data[i]-item[i];
		num=num/(time/16.6);
		values[i]=num;
	}
	let result=data;
	MTween.loop(item,values,time,callBack,result);
}
MTween.by=(item,data,time,callBack)=>{
	//console.log(data)
	let values={};
	for(let i in data){
		let num=data[i];
		num=num/(time/16.6);
		values[i]=num;
	}
	let result={};
	for(let i in data){
		let num=data[i]+item[i];
		result[i]=num;
	}
	MTween.loop(item,values,time,callBack,result);
}
//外部不使用此方法
MTween.loop=(item,values,time,callBack,result)=>{
	let [hz,count]=[16.6,0];
	item.mLoop=()=>{
		if(count<time){
			for(let i in values){
				//console.log(values[i]);
				item[i]+=values[i];
			}
			count+=hz;
			item.mTime=setTimeout(item.mLoop,hz);
		}else{
			if(result){
				for(let i in result)item[i]=result[i];
				//console.log(result)
			}
			callBack&&callBack();
		}
	}
	item.mLoop();
}
class MShape extends createui.Shape{
	constructor(){super();}
	clear(){this.graphics.clear();return this;}//清空
	drawRect(x,y,w,h){this.graphics.drawRect(x,y,w,h,this.c);return this;}//画方形
	drawCircle(x,y,r){this.graphics.drawCircle(x,y,r,this.c);return this;}//画圆形
	beginFill(c){this.c=c;if(uiStatus===uistat.createjs)this.graphics.beginFill(c);return this;}//填充颜色
	endFill(){if(uiStatus===uistat.createjs)this.graphics.endFill();return this;}//结束填充
	drawRoundRectComplex(x,y,w,h,rTL,rTR,rBR,rBL){//画圆角方形
		if(uiStatus===uistat.createjs){
			this.graphics.drawRoundRectComplex(x,y,w,h,rTL,rTR,rBR,rBL);
		}else if(uiStatus===uistat.laya){
			var max = (w<h?w:h)/2, mTL=0, mTR=0, mBR=0, mBL=0;
			if (rTL < 0) { rTL *= (mTL=-1); }if (rTL > max) { rTL = max; }if (rTR < 0) { rTR *= (mTR=-1); }if (rTR > max) { rTR = max; }if (rBR < 0) { rBR *= (mBR=-1); }if (rBR > max) { rBR = max; }if (rBL < 0) { rBL *= (mBL=-1); }if (rBL > max) { rBL = max; }
			var path =  [["moveTo", 0, 0],["lineTo",x+w-rTR, 0],["arcTo",x+w+rTR*mTR, 0-rTR*mTR, x+w, 0+rTR, rTR],["lineTo",x+w, 0+h-rBR],["arcTo",x+w+rBR*mBR, 0+h+rBR*mBR, x+w-rBR, 0+h, rBR],["lineTo",x+rBL, 0+h],["arcTo",x-rBL*mBL, 0+h+rBL*mBL, x, 0+h-rBL, rBL],["lineTo",x, 0+rTL],["arcTo",x-rTL*mTL, 0-rTL*mTL, x+rTL, 0, rTL]];
			this.graphics.drawPath(x, y, path, {fillStyle:this.c});
		}
		return this;
	}
	drawEllipse(x,y,w,h){//画一个椭圆
		this.g.drawEllipse(x,y,w,h);
		return this;
	}
	drawPolyStar(x, y, radius, sides, pointSize, angle){//画一个多边形星形
		this.g.drawPolyStar(x, y, radius, sides, pointSize, angle);
		return this;
	}
	drawRoundRect(x,y,w,h,r){//画圆角方形(一个r控制4个角)
		if(uiStatus===uistat.createjs){
			this.g.drawRoundRect(x,y,w,h,r);
		}
		return this;
	}
	/**画月亮 d厚度1-5,值越小越厚，r半径*/
	drawMoon(d=2,r=50){
		this.scale=r;
		this.g.arc(0, 0, 1, 0.5 * Math.PI, 1.5 * Math.PI, true);
		this.g.moveTo(0, -1);
		this.g.arcTo(d, 0, 0, 1, dis(0, -1, d, 0) / d);
		this.g.closePath()
		function dis(x1, y1, x2, y2) {
            return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }
		return this;
	}
	/**画梯形 */
	drawTrapezoid(x=0,y=0,top=10,bottom=20,height=30){
		let [t,b,h]=[top/2,bottom/2,height]
		this.g.moveTo(x, y);
		this.g.lineTo(t, y);
		this.g.lineTo(b, h);
		this.g.lineTo(x, h);
		this.g.lineTo(-b, h);
		this.g.lineTo(-t, y);
		return this;
	}
	/**画圆弧*/
	arc(x, y, radius, startAngle, endAngle, anticlockwise){
		if(uiStatus===uistat.createjs){
			this.g.arc(x, y, radius, startAngle, endAngle, anticlockwise);
		}
		return this;
	}
	/**设置线宽和颜色*/
	setLineSizeAndColor(s,c){
		if(uiStatus===uistat.createjs){
			this.g.setStrokeStyle(s);
			this.g.beginStroke(c);
		}
		return this;
	}
	/**设置位置*/
	setPos(x,y){
		x&&(this.x=x);
		y&&(this.y=y);
		return this;
	}
	/**重置皮肤*/
	resetSkin(c,stroke){
		this.clear();
		this.beginFill(c);
		if(stroke)this.setLineSizeAndColor(stroke.s,stroke.c)
	}
	/**画方形边框*/
	drLine(w,h,s=1,c=mColor.colorNormal){
		this.setLineSizeAndColor(s,c)
		this.drawRect(0,0,w,h);
		return this;
	}
	/**画圆形边框*/
	dcLine(r,s=1,c=mColor.colorNormal){
		this.setLineSizeAndColor(s,c)
		this.drawCircle(0,0,r);
		return this;
	}
	/***画方形的简单方法 */
	dr(w,h,c=mColor.colorNormal,s=null){
		this.resetSkin(c,s);
		this.drawRect(0,0,w,h);
		return this;
	}
	/***画圆角方形的简单方法 */
	drr(w,h,r,c=mColor.colorNormal,s=null){
		this.resetSkin(c,s);
		this.drawRoundRect(0,0,w,h,r);
		return this;
	}
	/***画圆形的简单方法 */
	dc(r,c=mColor.colorNormal,s=null){
		this.resetSkin(c,s);
		this.drawCircle(0,0,r);
		return this;
	}
	/***画圆弧(切西瓜片)的简单方法 */
	da(radius, startAngle=0, endAngle=2*Math.PI,c=mColor.colorNormal,s=null, anticlockwise=false){
		this.resetSkin(c,s);
		this.g.moveTo(0,0);
		this.arc(0,0,radius, startAngle, endAngle, anticlockwise);
		this.g.endStroke();
		this.g.closePath();
		return this;
	}
	/***画多边形polygon
	 * r半径，n边数
	*/
	dp(r,n,c=mColor.colorNormal,s=null){
		this.resetSkin(c,s);
		let angle=0;
		this.g.moveTo(0,0)
		for (let i=0; i <= n; ++i) {
			let[x,y]=[(r * Math.sin(angle)),(r * Math.cos(angle))];
			this.g.lineTo(x,y);
			angle += 2*Math.PI/n;
		}
		return this;
	}
	/**画一个椭圆*/
	de(w,h,c=mColor.colorNormal,s=null){
		this.resetSkin(c,s);
		this.g.drawEllipse(0,0,w,h);
		return this;
	}
	/**画一个多边形星形*/
	dps(radius,sides,pointSize,c=mColor.colorNormal,angle,s=null){
		this.resetSkin(c,s);
		this.g.drawPolyStar(0, 0, radius, sides, pointSize, angle);
		return this;
	}
	/**画一个月亮*/
	dm(d=2,r=30,c=mColor.colorNormal){
		this.resetSkin(c,null);
		this.drawMoon(d,r);
		return this;
	}
	/**画一个梯形*/
	dt(t=50,b=100,h=50,c=mColor.colorNormal,s=null){
		this.resetSkin(c,null);
		this.drawTrapezoid(0,0,t,b,h);
		return this;
	}
	f(c){
		this.beginFill(c);
		return this;
	}
	get g(){
		return this.graphics;
	}
	removeSelf(){
		if(this.parent){
			this.parent.removeChild(this);
		}
	}
}
class MBasice extends createui.Container{
	constructor(){
		super();
		this.setColor({})
	}
	setColor({normal=mColor.colorNormal,down=mColor.colorDown,over=mColor.colorOver,noActive=mColor.colorNoActive,back=mColor.colorBack,front=mColor.colorFront}){
		this.colorNormal=normal;
		this.colorDown=down;
		this.colorOver=over;
		this.colorNoActive=noActive;
		this.colorBack=back;
		this.colorFront=front;
		return this;
	}
	setPosition(da){
		da.x&&(this.x=da.x);
		da.y&&(this.y=da.y);
		return this;
	}
	getPosition(){
		return {x:this.x,y:this.y}
	}
	setPos(x,y){
		x&&(this.x=x);
		y&&(this.y=y);
		return this;
	}
	setWH(w,h){
		w&&(this.width=w);
		h&&(this.height=h);
		return this;
	}
	setScale(x,y){
		x&&(this.scaleX=x);
		y&&(this.scaleY=y);
		return this;
	}
	setAlpha(a){
		a&&(this.alpha=a);
		return this;
	}
	setRotation(r){
		r&&(this.rotation=r);
		return this;
	}
	createText(label){
		this.text=new createui.Text(label,'18px Arial',mColor.colorFont);
		if(uiStatus===uistat.createjs){
			this.text.regY=8;
			this.text.textAlign='center';
			this.text.lineHeight=22;
		}else if(uiStatus===uistat.laya){
			this.text.fontSize = 18;
            this.text.color = "#fff";
			this.text.text=label;
		}
		this.addChild(this.text);
		return this;
	}
	setText(label){
		(this.text)&&(this.text.text=label);
		this.updateTextPos();
		return this;
	}
	getText(){
		return this.text;
	}
	setCallBack(callBack){
		this.callBack=callBack;
		return this;
	}
	updateTextPos(){
		let [w,h]=[0,0];
		if(uiStatus===uistat.laya){
			w=this.text.width;h=this.text.height;
		}
		if(this.text){
			this.text.x=(this.width-w)>>1;
			this.text.y=(this.height-h)>>1;
		}
		return this;
	}
	addEvent(eventType,callBack){		cuiEvent.addEvent(this,eventType,callBack,this)	    }
	emitEvent(eventType,data){			cuiEvent.emitEvent(this,eventType,data)				}
	removeEvent(eventType,callBack){	cuiEvent.removeEvent(this,eventType,callBack,this)	}
	//左向右排版/右向左排版
	displayRank(array,xNum=1,xDis=0,yDis=0,x=0,y=0,sign=1){
		for(let i=0;i<array.length;i++){
			let display=array[i];
			display.x=x+parseInt(i%xNum)*(display.width+xDis)*sign;
			display.y=y+parseInt(i/xNum)*(display.height+yDis)*sign;
		}
	}
	//居中排版,每个显示对象锚点必须在左上角
	centerLayout=(array,xNum=1,xDis=10,yDis=10,x=0,y=0)=>{
		let display=array[0];
		let len=array.length;
		xNum=Math.min(len,xNum);
		let halfX=((xNum*(display.width+xDis)-xDis)>>1);
		let halfY=((parseInt(len/xNum)*(display.height+yDis)-yDis)>>1);
		for(let i=0;i<array.length;i++){
			let display=array[i];
			display.x=x+parseInt(i%xNum)*(display.width+xDis)-halfX;
			display.y=y+parseInt(i/xNum)*(display.height+yDis)-halfY;
		}
	}
	/**检查是否可以拖动，子类可以写条件（如MWindow）*/
	checkDrag(e){
		return true;
	}
	//拖动
	startDrag(){
		var oldX,oldY,isDrag;
		let events=['','pressmove','mousemove'];
		let eventType=events[uiStatus]; 
		this.addEvent("mousedown",mousedown);
		this.addEvent(eventType,mousemove);
		this.addEvent('pressup',mouseup);
		function mousedown(e){
			if(this.checkDrag(e)){
				oldX = e.stageX;
				oldY = e.stageY;
				isDrag=true;
			}
		}
		function mousemove(e){
			if(isDrag){
				this.x += e.stageX - oldX;
				this.y += e.stageY - oldY;
				oldX = e.stageX;
				oldY = e.stageY;
			}
		}
		function mouseup(e){
			isDrag=false;
		}
	}
	noEventBg(){
		var mask =  new MShape();
		mask.beginFill("#000000").drawRect(0,0,window.innerWidth,window.innerHeight);
		mask.alpha=0.3;
		mask.x=-this.x;mask.y=-this.y;
		mask.mouseEnabled=true;
		mask.mouseThrough = true;
		//空的-用于阻挡下面的鼠标事件
		cuiEvent.addEvent(mask,'click',function (e){e.stopPropagation();},this);
		this.addChildAt(mask,0);
	}
	destroy(){
		this.removeAllChildren();
		if(this.text){
			this.text.parent&&this.text.parent.removeChild(this.text);
			this.text=null;
		}
		this.parent&&this.parent.removeChild(this);
	}
	removeFromParent(dis=false){
		this.parent&&this.parent.removeChild(this);
		dis&&this.destroy();
	}
	removeSelf(dis=false){
		this.removeFromParent(dis);
	}
	removeAllChildren(){
		super.removeAllChildren();
	}
	setSkinColors(...arg){
		this.skinColors=arg;
	}
	setBgColor(color){}
	updateSkin(){}
}
class MSprite extends MBasice{
	constructor(){
		super();
		this.shape=new MShape();		this.addChild(this.shape);
	}
	setCenter(){
		if(this.drawData.funName)
		this.shape.x=-this.width/2;
		this.shape.y=-this.height/2;
	}
	clear(){
		this.removeAllChildren();
		this.shape.clear();
	}
	/***画方形的简单方法 */
	dr(w,h,c=mColor.colorNormal,s=null){
		this.drawData={funName:'dr',params:[w,h,c,s]};
		[this.width,this.height]=[w,h];	
		this.shape.dr(w,h,c,s);	
		return this;
	}
	/***画圆角方形的简单方法 */
	drr(w,h,r,c=mColor.colorNormal,s=null){
		this.drawData={funName:'drr',params:[w,h,r,c,s]};
		[this.width,this.height]=[w,h];	
		this.shape.drr(w,h,r,c,s);
		return this;
	}
	/***画圆形的简单方法 */
	dc(r,c=mColor.colorNormal,s=null){
		this.drawData={funName:'dc',params:[r,c,s]};
		[this.width,this.height]=[r*2,r*2];
		this.shape.dc(r,c,s);	
		return this;
	}
	/***画圆弧(切西瓜片)的简单方法 */
	da(radius, startAngle, endAngle,c=mColor.colorNormal,s=null, anticlockwise=false){
		this.drawData={funName:'da',params:[radius, startAngle, endAngle,c,s, anticlockwise]};
		[this.width,this.height]=[radius*2,radius*2];
		this.shape.da(radius, startAngle, endAngle,c,s,anticlockwise);
		return this;
	}
	/***画多边形polygon*/
	dp(r,n,c=mColor.colorNormal,s=null){
		this.drawData={funName:'dp',params:[r,n,c,s]};
		[this.width,this.height]=[r*2,r*2];
		this.shape.dp(r,n,c,s);										
		return this;
	}
	/**画一个椭圆*/
	de(w,h,c=mColor.colorNormal,s=null){
		this.drawData={funName:'de',params:[w,h,c,s]};
		[this.width,this.height]=[w*2,h*2];
		this.shape.de(w,h,c,s);										
		return this;
	}
	/**画一个多边形星形(默认画五角星)*/
	dps(radius,sides=5,pointSize=2,c=mColor.colorNormal,angle=-18,s=null){
		this.drawData={funName:'dps',params:[radius,sides,pointSize,c,angle,s]};
		[this.width,this.height]=[radius*2,radius*2];
		this.shape.dps(radius,sides,pointSize,c,angle,s);			
		return this;
	}
	/**画一个月亮*/
	dm(d=2,r=30,c=mColor.colorNormal){
		this.drawData={funName:'dm',params:[d,r,c]};
		[this.width,this.height]=[r*2,r*2];
		this.shape.dm(d,r,c);	
		return this;
	}
	/**画一个梯形*/
	dt(t=50,b=100,h=50,c=mColor.colorNormal,s=null){
		this.drawData={funName:'dt',params:[t,b,h,c,s]};
		[this.width,this.height]=[t>b?t:b,h];
		this.shape.dt(t,b,h,c,s);	
		return this;
	}
	createLabel(c='white'){
		let label=new MLabel({label:'',c:c});
		label.setPos(this.width/2,this.height/2);
		this.label=label;
        this.addChild(label);
	}
	set color(c){
		this.shape.clear();
		if(this.drawData){
			let[name,ps]=[this.drawData.funName,this.drawData.params];
			if(name=='dc') 												ps[1]=c;
			else if(name=='de'||name=='dr'||name=='dp'||name=='dm') 	ps[2]=c;
			else if(name=='drr'||name=='da'||name=='dps'||name=='dt') 	ps[3]=c;
			this[name](ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8]);
		}
	}
	get color(){
		let c='white';
		if(this.drawData){
			let[name,ps]=[this.drawData.funName,this.drawData.params];
			if(name=='dc') 												c=ps[1];
			else if(name=='de'||name=='dr'||name=='dp'||name=='dm')		c=ps[2];
			else if(name=='drr'||name=='da'||name=='dps'||name=='dt') 	c=ps[3];
		}
		return c;
	}
	get g(){		
		return this.shape.graphics;		
	}
}
class MLayer extends MBasice{
	constructor({color='#0099CC',width=200,height=200}) {
		super();
		if(!createui.stage){console.error('createui.stage未赋值');return;}
		this.skinBg=new MShape();
		this.addChild(this.skinBg);
		this.setWH(width,height);
		this.setBgColor(color);
	}
	setBgColor(color){
		this.color=color;
		if(this.skinBg)this.skinBg.clear().beginFill(color).drawRect(0, 0, this.width, this.height);
		return this;
	}
	updateSkin(){
		this.setBgColor(this.color);
		return this;
	}
}
class MMap extends MBasice{
	constructor({color='white',width=20,height=20}) {
		super();
		this.color=color;
		this.setMinWidHei(width,height);
		this.setSc();
	}
	setMinWidHei(width=20,height=20){
		this.minWid=width;
		this.minHei=height;
	}
	setNum(xNum=10,yNum=10){
		this.xNum=xNum;
		this.yNum=yNum;
		return this;
	}
	setSc(s=1,c='black'){
		this.s={s:s,c:c};
		return this;
	}
	setColor2(c='green'){
		this.color2=c;
		return this;
	}
	removeMaps(){
		if(this.nodes)this.nodes.forEach(map=>{map.removeSelf(true);});
	}
	create(type='dr'){
		this.removeMaps();
		this.maps=[];//二维数组
		this.nodes=[];//一维数组
		let [c,s]=[this.color,this.s];
		for(let i=0;i<this.yNum;i++){
			let maps=[];
			for(let j=0;j<this.xNum;j++){
				let map=new MSprite();
				if(this.color2)c=(i+j)%2==0?this.color:this.color2;
				if(type=='dr')map.dr(this.minWid,this.minHei,c,s);
				else if(type=='dc')map.dc(this.minWid/2,c,s);
				map.setPos(j*this.minWid,i*this.minHei);
				[map.px,map.py]=[j,i];
				this.addChild(map);
				maps.push(map);
				this.nodes.push(map);
			}
			this.maps.push(maps);
		}
	}
	createByMSprite(sprite){
		this.removeMaps();
		if(sprite.drawData){
			this.maps=[];//二维数组
			this.nodes=[];//一维数组
			let [c,s]=[this.color,this.s];
			for(let i=0;i<this.xNum;i++){
				let maps=[];
				for(let j=0;j<this.yNum;j++){
					let map=new MSprite();
					map.drawData=sprite.drawData;
					if(this.color2)c=(i+j)%2==0?this.color:this.color2;
					map.color=c;
					map.setPos(j*this.minWid,i*this.minHei);
					[map.px,map.py]=[j,i];
					this.addChild(map);
					maps.push(map);
					this.nodes.push(map);
				}
				this.maps.push(maps);
			}
		}
	}
}
class MScene extends MLayer{
	constructor({color='#159936'}) {
		super({color,width:createui.stageWidth,height:createui.stageHeight});
	}
}
class MLabel extends MBasice{
	constructor({label='文本',c=mColor.colorFont,width=80,height=30}) {
		super();
		this.setWH(width,height);
		this.createText(label);
		this.text.color=c;
	}
	createBg(c='white',r=5,isCenter=true,x=8,y=16){
		let bg=new MSprite();
		bg.drr(this.width,this.height,r,c);
		if(isCenter)[this.text.x,this.text.y]=[this.width/2,this.height/2];
		else		[this.text.x,this.text.y]=[x,y];
		this.addChildAt(bg,0);
	}
	setOutLine(s=2,c='black'){
		if(!this.out){
			this.out=new MLabel({});
			this.addChildAt(this.out,0);
		}
		this.out.text.color=c;
		this.out.text.outline=s;
		this.out.text.text=this.text.text;
		this.out.text.font=this.text.font;
		this.out.text.textAlign=this.text.textAlign;
	}
	subStrRemove(value,n='|'){//删除字符串末尾n个字符
		if(value.includes(n)){
			let vs=value.split(n);
			return vs[0]+vs[1];
		}else{
			return value;
		}
    }
	setLightFocus(){//光标闪烁
		if(this.text&&this.parent&&this.visible){
			let v=this.value;
			if(v.length>0){
				if(v.indexOf('|')>=0) 		this.value=this.subStrRemove(v);
				else if(v.indexOf('|')==-1)	this.value+='|';
			}
			setTimeout(()=>{this.setLightFocus()},500);
		}
	}
	setLeft(){this.text.textAlign='left';		return this;	}
	setRight(){this.text.textAlign='right';		return this;	}
	setCenter(){this.text.textAlign='center';	return this;	}
	set fontSize(val){this.text.font=val+'px Arial'}
	set color(val){this.text.color=val; }
	set value(val){this.text.text=val;	}
	get value(){return this.text.text;	}
	
}
class MButton extends MBasice{
	constructor({label='按钮',width=80,height=30,callBack=null}) {
		super();
		this.isCenter=false;
		this.callBack=callBack;
		this.setWH(width,height);
		this.skinNormal=new MShape();
		this.addChild(this.skinNormal);
		this.createText(label);
		this.setEnabled(true);
		this.updateSkin();
		return this;
	}
	setBgColor(color){
		if(this.skinNormal){
			let r=uiconfig.roundAngle;
			let [x,y]=[0,0]
			if(this.isCenter){
				[x,y]=[-this.width/2,-this.height/2];
			}
			this.skinNormal.clear().beginFill(color).drawRoundRectComplex(x, y, this.width, this.height, r, r, r, r);
		}
		return this;
	}
	setSkinColors(...arg){
		this.skinColors=arg;
		this.setBgColor(this.skinColors[0]);
		return this;
	}
	updateSkin(){
		this.setBgColor(this.colorNormal);
		this.updateTextPos();
		if(this.isCenter){
			this.text.x=this.text.y=0;
		}
		return this;
	}
	setEnabled(value) {
		if (value === this._enabled) { return; }
		this._enabled = value;
		this.mouseEnabled=value;
		this.tickEnabled=value;
		let eventTyps=["mouseout","mouseover","mousedown","pressup","click"];
		if (value) {
			this.setBgColor(this.colorNormal);
			this.cursor = "pointer";
			for(let i=0;i<eventTyps.length;i++) this.addEvent(eventTyps[i],this.handleEvent.bind(this));
		} else {
			this.setBgColor(this.colorNoActive);
			this.cursor = null;
			for(let i=0;i<eventTyps.length;i++) this.removeEvent(eventTyps[i],this.handleEvent.bind(this));
		}
	};
	handleEvent(evt) {
		if(this.mouseEnabled){
			let scs=this.skinColors;
			let type = evt.type;
			if (type === "mouseout")			this.setBgColor(scs?scs[0]:this.colorNormal);
			else if (type === "mouseover")		this.setBgColor(scs?scs[1]:this.colorOver);
			else if (type === "mousedown")		{this.setBgColor(scs?scs[2]:this.colorDown);this.cbDown&&this.cbDown(this)}
			else if (type === "pressup")		{this.setBgColor(scs?scs[0]:this.colorNormal);this.cbUp&&this.cbUp(this)}
			else if (type === "click")		   {this.setBgColor(scs?scs[1]:this.colorOver);this.callBack&&this.callBack(this)}
		}
	};
	destroy(){
		super.destroy();
		this.setEnabled(false);
		this.removeChild(this.skinNormal);
		this.skinNormal=null;
		this.callBack=null;
	}
}
//圆按钮
class MCircleButton extends MButton{
	constructor({label='按钮',radius=30}) {super({label,width:radius*2,height:radius*2});this.radius=radius;}
	setBgColor(color){
		this.radius=this.radius||this.width>>1;
		this.skinNormal.clear().beginFill(color).drawCircle(0,0,this.radius);
		this.skinNormal.x=this.radius;this.skinNormal.y=this.radius;
	}
}
//开关按钮
class MToggle extends MButton{
	constructor({width=80,height=30,colorOut=mColor.colorFront,colorInt=mColor.colorBack}) {
		super({label:'no',width,height});
		this.text.width=30;
		this._value=0;
		this.status=['no','yes'];
		this.colors=[colorOut,colorInt];
		this.skinBg=new MShape();
		this.addChildAt(this.skinBg,0);
		this.value=this._value;
	}
	setSkinColor(color,skin){
		let r=uiconfig.roundAngle;
		if(skin==this.skinBg){
			skin.clear().beginFill(color).drawRoundRectComplex(0, 0, this.width, this.height, r, r, r, r);
		}else{
			let w=this.width/2;
			let x=this.value?0:w;
			skin.clear().beginFill(color).drawRoundRectComplex(x, 0, w, this.height, r, r, r, r);
		}
		return this;
	}
	setSkinColors(...arg){
		this.colors=arg;
		this.setSkinColor(this.colors[0],this.skinBg);
		this.setSkinColor(this.colors[1],this.skinNormal);
		return this;
	}
	handleEvent(evt) {
		if(this.mouseEnabled){
			if (evt.type === "click"){
				this._value=1-this._value;
				this.value=this._value;
				this.callBack&&this.callBack(this);
			}			
		}
	}
	updateTextPos(){
		super.updateTextPos();
		this.text.x=this.value?60:20;
	}
	set value(_value){
		_value=_value?1:0;
		this.setText(this.status[_value]);
		this.setSkinColor(this.colors[_value],this.skinBg);
		this.setSkinColor(this.colorNormal,this.skinNormal);
		this._value=_value;
	}
	get value(){
		return this._value;
	}
}
//多个按钮
class MMoreButton extends MBasice{
	constructor(...arg) {
		super();
		this.buttons=[];
		for(let i=0;i<arg.length;i++){
			if(arg[i] instanceof MButton){
				let btn=arg[i];
				btn.index=i;
				btn.addEvent(mConst.CLICK,this.onClick.bind(this));
				this.addChild(btn);
				this.buttons.push(btn);
			}else{
				console.error('参数错误');
			}
		}
		this.index=this.buttons.length;
		this.selectBtn();
	}
	selectBtn(){
		this.index++;
		if(this.index>=this.buttons.length)this.index=0;
		this.buttons.forEach(btn=>btn.visible=false);
		this.buttons[this.index].visible=true;
	}
	onClick(e){
		this.selectBtn();
		this.emitEvent(mConst.CLICK);
	}
}
/**只画边框*/
class MStroke extends MBasice{
	constructor() {
		super();
		this.skin=new MShape();
		this.addChild(this.skin);
	}
	dr(w,h,s,c){
		this.skin.clear();
		this.skin.graphics.setStrokeStyle(s);
		this.skin.graphics.beginStroke(c);
		this.skin.graphics.drawRect(0,0,w,h,c);
		return this;
	}
	drr(w,h,s,c,r){
		this.skin.clear();
		this.skin.graphics.setStrokeStyle(s);
		this.skin.graphics.beginStroke(c);
		this.skin.graphics.drawRoundRect(0,0,w,h,c,r);
		return this;
	}
	dc(r,s,c){
		this.skin.clear();
		this.skin.graphics.setStrokeStyle(s);
		this.skin.graphics.beginStroke(c)
		this.skin.graphics.drawCircle(0,0,r);
		return this;
	}
}
class MTipBg extends MBasice{
	constructor({width=240,height=120,bottomHeight=40,topHeight=40}) {
		super();
		this.setWH(width,height);
		this.bottomHeight=bottomHeight;
		this.topHeight=topHeight;
		this.initView();
	}
	initView(){
		this.skinTop=new MShape();
		this.addChild(this.skinTop);
		this.skinBottom=new MShape();
		this.addChild(this.skinBottom);
		this.createText('');
		this.updateSkin();
	}
	updateSkin(){
		let r=uiconfig.roundAngle;
		this.skinTop.clear().beginFill(this.colorBack).drawRoundRectComplex(0, 0, this.width, this.height, r, r, r, r);
		let y=this.height-this.bottomHeight;
		this.skinBottom.clear().beginFill(this.colorFront).drawRoundRectComplex(0, y, this.width, this.bottomHeight, 0, 0, r, r);
		return this;
	}
	updateTextPos(){
		super.updateTextPos();
		let rect=this.text.getBounds();
		let bh=this.bottomHeight||0;
		this.text.regY=0;
		this.text.y=(this.height-bh-rect.height)>>1;
		return this;
	}
	destroy(){
		super.destroy();
		this.removeChild(this.skinTop);
		this.skinTop=null;
		this.removeChild(this.skinBottom);
		this.skinBottom=null;
	}
}
class MAlert extends MTipBg{
	constructor({label='提示',width=240,height=120,bottomHeight=40,topHeight=40}) {
		super({width,height,bottomHeight,topHeight});
		this.setText(label);
		this.updateTextPos();
		this.createButton();
		this.updateSkin();
	}
	createButton(){
		this.btn=new MButton({label:'确定'});
		this.btn.setCallBack(this.destroy.bind(this));
		this.addChild(this.btn);
	}
	updateSkin(){
		super.updateSkin();
		if(this.btn){
			this.btn.x=(this.width-this.btn.width)>>1;
			this.btn.y=(this.height-this.bottomHeight)+((this.bottomHeight-this.btn.height)>>1);
		}
		return this;
	}
	destroy(){
		super.destroy();
		if(this.btn){
			this.btn.destroy();
			this.btn=null;
		}
	}
}
class MSureCancel extends MAlert{
	constructor({label='提示',width=240,height=120,bottomHeight=40}) {
		super({label,width,height,bottomHeight});		
	}
	createButton(){
		this.btn1=new MButton({label:'确定'});
		this.addChild(this.btn1);
		this.btn2=new MButton({label:'取消'});
		this.addChild(this.btn2);
		this.btn1.setCallBack(this.onClick.bind(this));
		this.btn2.setCallBack(this.onClick.bind(this));
	}
	updateSkin(){
		super.updateSkin();
		if(this.btn1){
			this.btn1.x=(this.width/2-this.btn1.width)>>1;
			this.btn1.y=(this.height-this.bottomHeight)+((this.bottomHeight-this.btn1.height)>>1);
			this.btn2.x=this.width/2+((this.width/2-this.btn2.width)>>1);
			this.btn2.y=this.btn1.y;
		}
		return this;
	}
	onClick(evt){
		this.type=evt===this.btn1?1:0;
		this.emitEvent(cuiEvent.sureCancel);
		this.callBack&&this.callBack(this.type);
		this.destroy();
	}
	destroy(){
		super.destroy();
		if(this.btn1){
			this.btn1.destroy();
			this.btn1=null;
			this.btn2.destroy();
			this.btn2=null;
		}
	}
}
class MWindow extends MAlert{
	constructor({label='窗口',width=240,height=120,topHeight=30,bottomHeight=5}){
		super({label,width,height,bottomHeight,topHeight});
		this.items=[];
		this.updateTextPos();
		this.createContainer();
	}
	updateTextPos(){
		super.updateTextPos();
		let rect=this.text.getBounds();
		this.text.regY=0;
		this.text.y=(this.topHeight-rect.height)>>1;
		return this;
	}
	createButton(){
		this.btn=new MButton({label:'x',width:25,height:25});
		this.btn.setPos(this.width-this.btn.width-3,3);
		this.btn.setCallBack(this.destroy.bind(this));
		this.addChild(this.btn);
	}
	removeCloseButton(){
		this.removeChild(this.btn);
	}
	updateSkin(){
		this.wallSize=2;
		let r=uiconfig.roundAngle;
		this.skinTop.clear().beginFill(this.colorBack).drawRoundRectComplex(0, 0, this.width, this.height, r, r, r, r);
		let h=this.height-this.bottomHeight-this.topHeight;
		let w=this.width-(this.wallSize<<1);
		this.skinBottom.clear().beginFill(this.colorFront).drawRoundRectComplex(this.wallSize, this.topHeight,w,h,0,0,r,r);
		return this;
	}
	createContainer(){
		this.container=new MBasice;
		this.container.setPos(this.wallSize,this.topHeight);
		this.addChild(this.container);
		let mask=new MShape();
		let h=this.height-this.bottomHeight-this.topHeight;
		let w=this.width-(this.wallSize<<1);
		let [x,y]=[0,0];
		if(uiStatus==uistat.createjs){
			x=this.wallSize;y=this.topHeight;
		}
		let r=uiconfig.roundAngle;
		mask.beginFill("#FF0000").drawRoundRectComplex(x,y,w,h,0,0,r,r);
		this.container.mask=mask;
	}
	addItem(item){//item可以是支持的引擎的显示对象
		this.items.push(item);
		this.container.addChild(item);
	}
	removeItem(item){
		this.items.splice(this.items.indexOf(item),1);
		this.container.removeChild(item);
	}
	checkDrag(e){
		return e.stageY-this.y<this.topHeight;
	}
	getItems(){	return this.items;	}
}
class MTabbar extends MBasice{
	constructor(gap=1){	super(); this.items=[];	this.gap=gap}
	addItem(item){//item必须是MButton或MCircleButton
		item.setCallBack(this.onTabbar.bind(this));
		item.id=this.items.length;
		item.x=(item.width+this.gap)*item.id;
		this.items.push(item);
		this.addChild(item);
	}
	removeItem(item){
		this.items.splice(this.items.indexOf(item),1);
		item.destroy();
	}
	getItems(){	return this.items;	}
	select(index){this.onTabbar(this.items[index])}
	onTabbar(item){
		this.items.forEach((item)=>{
			item.setEnabled(true);
		})
		item.setEnabled(false);
		this.callBack&&this.callBack(item.id);
		this.index=item.id;
		this.emitEvent(mConst.CHANGE)
	}
}
/**单选框或多选框，type=1是单选，type=2是多选 */
class MToggleContainer extends MBasice {
    constructor({type=1,outColor=mColor.colorBack,inColor=mColor.colorFront,labColor=mColor.colorFront}){
        super();
        this.type=type;
        this.outColor=outColor;
        this.inColor=inColor;
        this.labColor=labColor;
        this.index=0;
        this.indexs=[];
    }
	setSkinColors(...arg){
		if(arg[0])this.outColor=arg[0];
        if(arg[1])this.inColor=arg[1];
        if(arg[2])this.labColor=arg[2];
	}
    create(arr){
        this.nodes=[];
        for(let i=0;i<arr.length;i++){
            let node=this.toggle(this.type);
            let label=new MLabel({label:arr[i]});
            label.color=this.labColor;
            label.anchorX=0;
            label.x=50;
            if(this.type==1){
				label.x=30;
			}else if(this.type==2){
				label.y=14;
			}
            node.addChild(label);
			node.label=label;
            node.y=i*40;
            this.addChild(node);
            this.nodes.push(node);
            node.index=i;
            //node.on(cc.Node.EventType.TOUCH_START,this.onTouch,this)
			node.addEvent("mousedown",this.onTouch.bind(this));
        }
    }
	setLabelPos(x,y){
		this.nodes.forEach((n)=>{
			if(x)n.label.x+=x;
			if(y)n.label.y+=y;
		})
	}
    toggle(type){
		var node=new MBasice();
        var bg=new MShape;
        var child=new MShape;
        node.addChild(bg);
		node.addChild(child);
        node.child=child;
		//console.log('type=',type)
        if(type==1){
            bg.dc(14,this.outColor);
            child.dc(10,this.inColor);
        }else{
            bg.dr(28,28,this.outColor);
            child.dr(18,18,this.inColor);
			child.x=child.y=5;
        }
        child.visible=false;
        return node;
    }
    select(...par){
        if(this.nodes.length==0)return;
        if(this.type==1){
            this.index=par[0];
            this.selectTaget(this.nodes[this.index]);
        }else{
            this.indexs=par;
            this.indexs.forEach(i=>{
                this.nodes[i].child.visible=true;
            })
        }
    }
    onTouch(e){
        let target=e.currentTarget;
        this.selectTaget(target);
    }
    selectTaget(target){
        if(this.type==1){
            this.index=target.index;
            this.nodes.forEach(node=>{
                node.child.visible=false;
            })
            target.child.visible=true;
        }else{
            target.child.visible=!target.child.visible;
            if(target.child.visible){
                this.indexs.push(target.index);
            }else{
                this.indexs=this.indexs.filter(i=>i!=target.index);
            }
        }
		this.emitEvent(mConst.CHANGE);
        //console.log(this.index,this.indexs);
    }
}
class MImage extends MBasice{
	constructor({url,isCenter=false,callBack}) {
		super();
		if(uiStatus===uistat.createjs){
			this.isCenter=isCenter;
			this.setSrc(url,callBack);
		}else if(uiStatus===uistat.laya){
			var sprite = new Laya.Sprite();
			this.addChild(sprite);
			sprite.loadImage(url,0,0,0,0,()=>{
				this.setWH(sprite.width,sprite.height);
			});
		}
	}
	setSrc(src,callBack){
		if(this.bitmap){
			this.removeChild(this.bitmap);
			this.bitmap=null;
		}
		var image=new Image();
		image.src=src;
		image.onload=(event)=>{
			var bitmap=new createjs.Bitmap(event.target);
			this.addChild(bitmap);
			this.setWH(bitmap.image.width,bitmap.image.height);
			if(this.isCenter){
				bitmap.x=-bitmap.image.width/2;
				bitmap.y=-bitmap.image.height/2;
			}
			this.bitmap=bitmap;
			callBack&&callBack();
		}
	}
	setAnchor(x=0,y=0){
		if(this.bitmap){//0,0锚点左上,0.5,0.5锚点中间,1,1锚点右下
			this.bitmap.x=-this.bitmap.width*x;
			this.bitmap.y=-this.bitmap.height*y;
		}
	}
}
//Scorll目前只支持createjs
class MScorll extends MWindow{
	constructor({width=200,height=200}) {
		super({label:'',width,height,bottomHeight:0,topHeight:0});
		this.removeCloseButton();
		this.startDrag();
	}
	updateSkin(){this.wallSize=0;}
	updateTextPos(){}
	addItem(item){//宽相同就是VScorll,高相同就是HScorll
		this.container.addChild(item);
		this.container.width=item.width;
		this.container.height=item.height;
	}
	startDrag(){
		let con=this.container
		let oldX,oldY,isDrag;
		let events=['','pressmove','mousemove'];
		let eventType=events[uiStatus]; 
		this.addEvent("mousedown",mousedown);
		this.addEvent(eventType,mousemove);
		this.addEvent('pressup',mouseup);
		function mousedown(e){
			oldX = e.stageX;
			oldY = e.stageY;
			isDrag=true;
		}
		function mousemove(e){
			if(isDrag){
				con.x += e.stageX - oldX;
				con.y += e.stageY - oldY;
				oldX = e.stageX;
				oldY = e.stageY;
				let [left,top,right,bottom]=[0,0,this.width-con.width,this.height-con.height];
				if(con.x>left)con.x=left;
				else if(con.x<right)con.x=right;
				if(con.y>top)con.y=top;
				else if(con.y<bottom)con.y=bottom;
			}
		}
		function mouseup(e){
			isDrag=false;
		}
	}
}
//进度条
class MProgress extends MBasice{
	constructor({width=200,height=20,r=0,colorOut=mColor.colorBack,colorInt=mColor.colorFront}) {
		super();
		this.width=width;this.height=height;
		this.r=r||uiconfig.roundAngle;
		r=this.r;

		this.skinBg=new MShape();
		this.addChild(this.skinBg);
		this.skinBg.beginFill(colorOut).drawRoundRectComplex(0, 0, this.width, this.height,r,r,r,r);
		
		this.skinBar=new MShape();
		this.addChild(this.skinBar);
		this.skinBar.beginFill(colorInt).drawRoundRectComplex(0, 0, this.width, this.height,r,r,r,r);
		
		this.skinMask=new MShape();
		this.skinMask.beginFill(colorOut).drawRect(0, 0, this.width, this.height)
		this.skinBar.mask=this.skinMask;
		this.initData();
	}
	setSkinColors(...arg){
		let r=this.r;
		if(arg[0]) this.skinBar.drr(this.width, this.height,r,arg[0]);
		if(arg[1]) this.skinBg.drr(this.width, this.height,r,arg[1]);
	}
	initData(){
		this.value=0;
	}
	setValue(_value){
		this.value=_value;
		return this;
	}
	set value(_value){
		_value=Math.min(1,_value);
		_value=Math.max(0,_value);
		this.skinMask.scaleX=_value;
		this._value=_value;
		this.update();
	}
	get value(){return this._value}
	update(){
		
	}
}
//滑动条
class MSlide extends MProgress{
	initData(){
		this.startDrag();
		this.initBar();
		this.value=0;
	}
	setBarColor(color){
		this.barColor=color;
		this.initBar();
	}
	setSkinColors(...arg){
		super.setSkinColors(arg[1],arg[2]);
		this.setBarColor(arg[0]);
	}
	initBar(){
		if(this.bar){
			this.bar.removeSelf();
			this.bar=null;
		}
		let hei=this.height*0.7;
		this.bar=new MShape();
		this.addChild(this.bar);
		this.bar.beginFill(this.barColor||mColor.colorNormal).drawCircle(0, 0,hei);
		this.bar.y=this.height/2;
		this.setBarVal();
	}
	startDrag(){
		let events=['','pressmove','mousemove'];
		let eventType=events[uiStatus];
		let isDrag=false;
		this.addEvent("mousedown",mousedown);
		this.addEvent(eventType,mousemove);
		this.addEvent('pressup',mouseup);
		function mousedown(e){isDrag=true;}
		function mouseup(e){isDrag=false;}
		function mousemove(e){
			if(isDrag){
				let x=0;
				if(uiStatus===uistat.createjs){
					x= this.globalToLocal(e.stageX,0).x;
				}else if(uiStatus===uistat.laya){
					x=this.globalToLocal(new createui.Point(e.stageX,0)).x;
				}
				this.value=x/this.width;
				if(this.callBack)this.callBack(this.value);
			}
		}
	}
	setBarVal(){
		let x=this.value*this.width;
		if(x>=0&&x<=this.width){
			this.bar.x=x;
		}
	}
	update(){
		this.setBarVal();
		this.emitEvent(mConst.CHANGE);
	}
}
//页码翻页控制器
class MNumPage extends MBasice{
	constructor({onePage=6,radius=30,total=10,gap=3}) {
		super();
		this.onePage=onePage;//可显示多少页
		this.radius=radius;//圆按钮半径
		this.total=total;//总共的页数
		this.curr=0;//当前页数
		this.currArrowPage=0;//当前箭头页数
		this.totalArrowPage=Math.ceil(total/onePage);//总共的箭头页数
		this.half=Math.ceil(onePage/2);//半页数
		let buttons=[];
		for (let i = 0; i < onePage; i++){
			let btn=new MCircleButton({ label: i + 1, radius: radius });
			btn.addEvent(mConst.CLICK,this.onUpdatePage.bind(this,i));
			buttons.push(btn);
			this.addChild(btn);
		} 
		this.displayRank(buttons,onePage,gap);
		this.buttons=buttons;

		this.arrows=[];
		for(let i=0;i<2;i++){
			let btn = new MCircleButton({label:'',radius: radius});
			let w=radius/2;
			let icon=(new MShape()).dp(w,3,'white').setPos(radius,radius);
			icon.rotation=i==0?90:-90;
			btn.addChild(icon);
			btn.addEvent(mConst.CLICK,this.onArrowClick.bind(this,i));
			this.addChild(btn);
			this.arrows.push(btn);
		}
		let rg=(radius+gap);
		let xDis=(radius*2+gap)*(onePage)+gap;
		let x=-rg*2+gap
		this.displayRank(this.arrows,2,xDis,0,x);
		this.onUpdatePage(0);
		this.width=xDis-x;
	}
	onArrowClick(i){
		//console.log(i)
		if(i==0){//左
			this.curr--;
		}else{//右
			this.curr++;
		}
		this.updateArrowPage();
	}
	updateArrowPage(){
		let pageNum=this.onePage;
		let current=this.curr;
		let total=this.total;
		let half=this.half;
		let btn=null;
		for(let i=0;i<pageNum;i++){
			btn=this.buttons[i];
			var label='';
			if(current<=half){
				label=String(i+1);
			}else if(current>total-half){
				label=String(total-pageNum+i+1);
			}else{
				label=String(current-half+i+1);
			}
			btn.setText(label);
			btn.setEnabled(true);
		}
		let index=0;
		if(current<=half){
			index=[current-1];
		}else if(current>total-half){
			index=[pageNum-(total-current)-1];
		}else{
			index=[half-1];
		}
		btn=this.buttons[index];
		btn.setEnabled(false);
		this.updateArrow();	
		this.emitEvent(mConst.CHANGE);
	}
	getIndex(){
		return this.curr;
	}
	onUpdatePage(i){
		let item=this.buttons[i];
		this.curr=Number(item.text.text);
		//console.log(this.curr);
		this.updateArrowPage();
	}
	setTotal(total){
		this.total=total;
		this.updateArrow();
	}
	updateArrow(){
		this.arrows.forEach(btn=>{
			btn.visible=this.total>this.onePage;
		})
		this.arrows.forEach((btn)=>{
			btn.setEnabled(true);
		})
		if(this.curr==1) this.arrows[0].setEnabled(false);
		else if(this.curr==this.total) this.arrows[1].setEnabled(false);
	}
}